home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #5 / Amiga Plus CD - 2000 - No. 5.iso / Tools / Dev / Real / gui / realprefs.c < prev    next >
C/C++ Source or Header  |  1996-03-25  |  7KB  |  262 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Miîosîaw Smyk
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/intuition_pragmas.h>
  27. #include <pragmas/gadtools_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/utility_pragmas.h>
  30.  
  31. #include "realprefs.h"
  32.  
  33. struct Screen         *Scr = NULL;
  34. UBYTE                 *PubScreenName = NULL;
  35. APTR                   VisualInfo = NULL;
  36. struct Window         *RealPrefsWnd = NULL;
  37. struct Gadget         *RealPrefsGList = NULL;
  38. struct IntuiMessage    RealPrefsMsg;
  39. struct Gadget         *RealPrefsGadgets[4];
  40. UWORD                  RealPrefsLeft = 250;
  41. UWORD                  RealPrefsTop = 265;
  42. UWORD                  RealPrefsWidth = 263;
  43. UWORD                  RealPrefsHeight = 49;
  44. UBYTE                 *RealPrefsWdt = (UBYTE *)"wfmhcybergfx_r3d.library";
  45. struct TextAttr       *Font, Attr;
  46. UWORD                  FontX, FontY;
  47. UWORD                  OffX, OffY;
  48. struct TextFont       *RealPrefsFont = NULL;
  49.  
  50. UBYTE *Gadget000Labels[] = {
  51.     (UBYTE *)"Floyd-Steinberg",
  52.     (UBYTE *)"Ordered 4x4",
  53.     (UBYTE *)"None",
  54.     NULL };
  55.  
  56. UWORD RealPrefsGTypes[] = {
  57.     CYCLE_KIND,
  58.     BUTTON_KIND,
  59.     BUTTON_KIND,
  60.     BUTTON_KIND
  61. };
  62.  
  63. struct NewGadget RealPrefsNGad[] = {
  64.     92, 6, 160, 14, (UBYTE *)"_Dithering", NULL, GD_Gadget00, PLACETEXT_LEFT, NULL, (APTR)Gadget00Clicked,
  65.     12, 30, 76, 14, (UBYTE *)"_Save", NULL, GD_Gadget10, PLACETEXT_IN, NULL, (APTR)Gadget10Clicked,
  66.     176, 30, 76, 14, (UBYTE *)"_Cancel", NULL, GD_Gadget20, PLACETEXT_IN, NULL, (APTR)Gadget20Clicked,
  67.     94, 30, 76, 14, (UBYTE *)"_Use", NULL, GD_Gadget30, PLACETEXT_IN, NULL, (APTR)Gadget30Clicked
  68. };
  69.  
  70. ULONG RealPrefsGTags[] = {
  71.     (GTCY_Labels), (ULONG)&Gadget000Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE),
  72.     (GT_Underscore), '_', (TAG_DONE),
  73.     (GT_Underscore), '_', (TAG_DONE),
  74.     (GT_Underscore), '_', (TAG_DONE)
  75. };
  76.  
  77. static UWORD ComputeX( UWORD value )
  78. {
  79.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  80. }
  81.  
  82. static UWORD ComputeY( UWORD value )
  83. {
  84.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  85. }
  86.  
  87. static void ComputeFont( UWORD width, UWORD height )
  88. {
  89.     Forbid();
  90.     Font = &Attr;
  91.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  92.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  93.     FontX = GfxBase->DefaultFont->tf_XSize;
  94.     Permit();
  95.  
  96.     OffX = Scr->WBorLeft;
  97.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  98.  
  99.     if ( width && height ) {
  100.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  101.             goto UseTopaz;
  102.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  103.             goto UseTopaz;
  104.     }
  105.     return;
  106.  
  107. UseTopaz:
  108.     Font->ta_Name = (STRPTR)"topaz.font";
  109.     FontX = FontY = Font->ta_YSize = 8;
  110. }
  111.  
  112. int SetupScreen( void )
  113. {
  114.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  115.         return( 1L );
  116.  
  117.     ComputeFont( 0, 0 );
  118.  
  119.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  120.         return( 2L );
  121.  
  122.     return( 0L );
  123. }
  124.  
  125. void CloseDownScreen( void )
  126. {
  127.     if ( VisualInfo ) {
  128.         FreeVisualInfo( VisualInfo );
  129.         VisualInfo = NULL;
  130.     }
  131.  
  132.     if ( Scr        ) {
  133.         UnlockPubScreen( NULL, Scr );
  134.         Scr = NULL;
  135.     }
  136. }
  137.  
  138. void RealPrefsRender( void )
  139. {
  140.     ComputeFont( RealPrefsWidth, RealPrefsHeight );
  141.  
  142.     DrawBevelBox( RealPrefsWnd->RPort, OffX + ComputeX( 0 ),
  143.                     OffY + ComputeY( 0 ),
  144.                     ComputeX( 263 ),
  145.                     ComputeY( 49 ),
  146.                     GT_VisualInfo, VisualInfo, TAG_DONE );
  147. }
  148.  
  149. int HandleRealPrefsIDCMP( void )
  150. {
  151.     struct IntuiMessage    *m;
  152.     int            (*func)();
  153.     BOOL            running = TRUE;
  154.  
  155.     while( m = GT_GetIMsg( RealPrefsWnd->UserPort )) {
  156.  
  157.         CopyMem(( char * )m, ( char * )&RealPrefsMsg, (long)sizeof( struct IntuiMessage ));
  158.  
  159.         GT_ReplyIMsg( m );
  160.  
  161.         switch ( RealPrefsMsg.Class ) {
  162.  
  163.             case    IDCMP_REFRESHWINDOW:
  164.                 GT_BeginRefresh( RealPrefsWnd );
  165.                 RealPrefsRender();
  166.                 GT_EndRefresh( RealPrefsWnd, TRUE );
  167.                 break;
  168.  
  169.             case    IDCMP_CLOSEWINDOW:
  170.                 running = RealPrefsCloseWindow();
  171.                 break;
  172.  
  173.             case    IDCMP_GADGETUP:
  174.                 func = ( void * )(( struct Gadget * )RealPrefsMsg.IAddress )->UserData;
  175.                 running = func();
  176.                 break;
  177.         }
  178.     }
  179.     return( running );
  180. }
  181.  
  182. int OpenRealPrefsWindow( void )
  183. {
  184.     struct NewGadget    ng;
  185.     struct Gadget    *g;
  186.     UWORD        lc, tc;
  187.     UWORD        wleft = RealPrefsLeft, wtop = RealPrefsTop, ww, wh;
  188.  
  189.     ComputeFont( RealPrefsWidth, RealPrefsHeight );
  190.  
  191.     ww = ComputeX( RealPrefsWidth );
  192.     wh = ComputeY( RealPrefsHeight );
  193.  
  194.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  195.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  196.  
  197.     if ( ! ( RealPrefsFont = OpenDiskFont( Font )))
  198.         return( 5L );
  199.  
  200.     if ( ! ( g = CreateContext( &RealPrefsGList )))
  201.         return( 1L );
  202.  
  203.     for( lc = 0, tc = 0; lc < RealPrefs_CNT; lc++ ) {
  204.  
  205.         CopyMem((char * )&RealPrefsNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  206.  
  207.         ng.ng_VisualInfo = VisualInfo;
  208.         ng.ng_TextAttr   = Font;
  209.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  210.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  211.         ng.ng_Width      = ComputeX( ng.ng_Width );
  212.         ng.ng_Height     = ComputeY( ng.ng_Height);
  213.  
  214.         RealPrefsGadgets[ lc ] = g = CreateGadgetA((ULONG)RealPrefsGTypes[ lc ], g, &ng, ( struct TagItem * )&RealPrefsGTags[ tc ] );
  215.  
  216.         while( RealPrefsGTags[ tc ] ) tc += 2;
  217.         tc++;
  218.  
  219.         if ( NOT g )
  220.             return( 2L );
  221.     }
  222.  
  223.     if ( ! ( RealPrefsWnd = OpenWindowTags( NULL,
  224.                 WA_Left,    wleft,
  225.                 WA_Top,        wtop,
  226.                 WA_Width,    ww + OffX + Scr->WBorRight,
  227.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  228.                 WA_IDCMP,    CYCLEIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  229.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  230.                 WA_Gadgets,    RealPrefsGList,
  231.                 WA_Title,    RealPrefsWdt,
  232.                 WA_ScreenTitle,    "wfmhcybergfx.library ©1995-96 Miloslaw Smyk",
  233.                 WA_PubScreen,    Scr,
  234.                 TAG_DONE )))
  235.     return( 4L );
  236.  
  237.     GT_RefreshWindow( RealPrefsWnd, NULL );
  238.  
  239.     RealPrefsRender();
  240.  
  241.     return( 0L );
  242. }
  243.  
  244. void CloseRealPrefsWindow( void )
  245. {
  246.     if ( RealPrefsWnd        ) {
  247.         CloseWindow( RealPrefsWnd );
  248.         RealPrefsWnd = NULL;
  249.     }
  250.  
  251.     if ( RealPrefsGList      ) {
  252.         FreeGadgets( RealPrefsGList );
  253.         RealPrefsGList = NULL;
  254.     }
  255.  
  256.     if ( RealPrefsFont ) {
  257.         CloseFont( RealPrefsFont );
  258.         RealPrefsFont = NULL;
  259.     }
  260. }
  261.  
  262.